home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / lt_findmenucommand.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  3KB  |  138 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <clib/keymap_protos.h>
  17. #include <pragmas/keymap_pragmas.h>
  18.  
  19. #include <stddef.h>
  20.  
  21. /*****************************************************************************/
  22.  
  23. #include "Assert.h"
  24.  
  25. /*****************************************************************************/
  26.  
  27. #ifdef DO_MENUS    /* Support code */
  28.  
  29. /****** gtlayout.library/LT_FindMenuCommand ******************************************
  30. *
  31. *   NAME
  32. *    LT_FindMenuCommand -- Get the menu/submenu item associated
  33. *                          with a rawkey event (V11)
  34. *
  35. *   SYNOPSIS
  36. *    Item = LT_FindMenuCommand(Menu,Code,Qualifier,Gadget)
  37. *     D0                        A0  D0       D0      A1
  38. *
  39. *    struct MenuItem *LT_FindMenuCommand(struct Menu *,
  40. *
  41. *                         UWORD,ULONG,struct Gadget *);
  42. *
  43. *   FUNCTION
  44. *    With the IntuiMessage data copied from a type IDCMP_RAWKEY message
  45. *    tries to find the MenuItem the event referred to.
  46. *
  47. *   INPUTS
  48. *    Menu - Pointer to Menu structure as returned by LT_NewMenuTagList.
  49. *
  50. *    Code - Value copied from IntuiMessage->Code
  51. *
  52. *    Qualifier - Value copied from IntuiMessage->Qualifier
  53. *
  54. *    Gadget - Value copied from IntuiMessage->IAddress
  55. *
  56. *   RESULT
  57. *    Item - Pointer to the struct MenuItem * in question or NULL
  58. *        if none could be found
  59. *
  60. *   SEE ALSO
  61. *    gtlayout.library/LT_NewMenuTagList
  62. *
  63. ******************************************************************************
  64. *
  65. */
  66.  
  67. struct MenuItem * LIBENT
  68. LT_FindMenuCommand(REG(a0) struct Menu *Menu,REG(d0) UWORD MsgCode,REG(d1) UWORD MsgQualifier,REG(a1) struct Gadget *MsgGadget)
  69. {
  70.     if(!Menu)
  71.         return(NULL);
  72.  
  73.         // Only take care of downstrokes
  74.  
  75.     if(!(MsgCode & IECODE_UP_PREFIX))
  76.     {
  77.         RootMenu            *Root = (RootMenu *)((ULONG)Menu - offsetof(RootMenu,Menu));
  78.         ItemNode            *Item;
  79.         struct InputEvent     Event;
  80.         UBYTE                 ANSIKey[10];
  81.         ULONG                 Qualifier;
  82.  
  83.             // Fix up the MsgQualifier
  84.  
  85.         if(MsgQualifier & QUALIFIER_SHIFT)
  86.             MsgQualifier = (MsgQualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
  87.  
  88.         if(MsgQualifier & QUALIFIER_ALT)
  89.             MsgQualifier = (MsgQualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
  90.  
  91.             // Convert the key
  92.  
  93.         ANSIKey[0] = 0;
  94.  
  95.         Event.ie_NextEvent        = NULL;
  96.         Event.ie_Class            = IECLASS_RAWKEY;
  97.         Event.ie_SubClass        = 0;
  98.         Event.ie_Code            = MsgCode;
  99.         Event.ie_Qualifier        = MsgQualifier;
  100.         Event.ie_EventAddress    = (APTR)MsgGadget;
  101.  
  102.         if(!MapRawKey(&Event,ANSIKey,9,NULL))
  103.             ANSIKey[0] = 0;
  104.  
  105.             // Run down the list...
  106.  
  107.         for(Item = (ItemNode *)Root->ItemList.mlh_Head ; Item->Node.mln_Succ ; Item = (ItemNode *)Item->Node.mln_Succ)
  108.         {
  109.                 // See if we can do with the char
  110.  
  111.             if(Item->Char)
  112.             {
  113.                 if(Item->Char == ANSIKey[0])
  114.                     return(&Item->Item);
  115.             }
  116.             else
  117.             {
  118.                     // So that didn't work, what about the raw data?
  119.  
  120.                 Qualifier = Item->Qualifier;
  121.  
  122.                 if(Qualifier & QUALIFIER_SHIFT)
  123.                     Qualifier = (Qualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
  124.  
  125.                 if(Qualifier & QUALIFIER_ALT)
  126.                     Qualifier = (Qualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
  127.  
  128.                 if(Item->Code == MsgCode && (MsgQualifier & Qualifier) == Qualifier)
  129.                     return(&Item->Item);
  130.             }
  131.         }
  132.     }
  133.  
  134.     return(NULL);
  135. }
  136.  
  137. #endif    /* DO_MENUS */
  138.